﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ConvoyOfHope_ConvoyOfHope : System.Web.UI.Page
{
    DataAccess App;
    int Sender;

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {

                if (Request.QueryString.HasKeys())
                {
                    if (Request.QueryString["listid"] != String.Empty)
                        Session["listid"] = Request.QueryString["listid"];
                    else
                        Session["listid"] = 1;

                    if (Request.QueryString["dnis"] != null)
                    {
                        Session["dnis"] = Request.QueryString["dnis"];
                    }
                    else
                    {
                        Session["dnis"] = "9999999999";
                    }

                    Session["servername"] = Request.QueryString["servername"];
                    Session["projectname"] = Request.QueryString["projectname"];
                    Session["campaignname"] = Request.QueryString["campaignname"];
                    Session["agentid"] = Request.QueryString["agentid"];
                    Session["agentfirst"] = Request.QueryString["agentfirst"];
                    Session["agentlast"] = Request.QueryString["agentlast"];

                }

                App = new DataAccess();
                Session["App"] = App;
                WebWizard.ActiveStepIndex = 2;
                App.PutCallData("ScriptStart", System.DateTime.Now.ToString());
                App.PutCallData("AgentFirst", Session["agentfirst"].ToString());
                App.PutCallData("AgentLast", Session["agentlast"].ToString());

                App.CommitCallData();
                Sender = 2;

            }
            else
            {
                App = (DataAccess)Session["App"];
                litAgentFirstName.Text = Session["agentfirst"].ToString();
            }
        }
        catch (Exception ex)
        {
            lblException.Visible = true;
            lblException.Text = "CONTACT IT/SUPERVISOR with the following information or screenshot:" + ex.ToString();
        }

    }

    //POST LOGIC - For Step or Start pages
    protected void WebWizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {
        try
        {
            int page = WebWizard.ActiveStepIndex;


            if (page == WebWizard.WizardSteps.IndexOf(this.Introduction))
            {

                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.ChildSponsor);
                return;
            }

            if (page == WebWizard.WizardSteps.IndexOf(this.MailLetter))
            {
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);
                return;
            }

            if (page == WebWizard.WizardSteps.IndexOf(this.ChildSponsor))
            {
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);
                return;
            }

            if (page == WebWizard.WizardSteps.IndexOf(this.OneTime))
            {
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);
                return;
            }
            if (page == WebWizard.WizardSteps.IndexOf(this.Rebuttals))
            {
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Rebuttals);
                return;
            }
            if (page == WebWizard.WizardSteps.IndexOf(this.FAQ))
            {
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.FAQ);
                return;
            }
            if (page == WebWizard.WizardSteps.IndexOf(this.Disposition))
            {

                return;
            }
        }
        catch (Exception ex)
        {
            lblException.Visible = true;
            lblException.Text = ex.ToString();
        }


    }

    //POST LOGIC for finish pages
    protected void WebWizard_FinishButtonClick(object sender, WizardNavigationEventArgs e)
    {
        try
        {
            int page = WebWizard.ActiveStepIndex;


            if (page == WebWizard.WizardSteps.IndexOf(this.Introduction))
            {
                return;
            }

            if (page == WebWizard.WizardSteps.IndexOf(this.MailLetter))
            {
                Sender = WebWizard.WizardSteps.IndexOf(this.MailLetter);
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);

                return;
            }

            if (page == WebWizard.WizardSteps.IndexOf(this.ChildSponsor))
            {
                Sender = WebWizard.WizardSteps.IndexOf(this.ChildSponsor);
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);

                return;
            }

            if (page == WebWizard.WizardSteps.IndexOf(this.OneTime))
            {
                Sender = WebWizard.WizardSteps.IndexOf(this.OneTime);
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);
                return;
            }
            if (page == WebWizard.WizardSteps.IndexOf(this.Rebuttals))
            {

                return;
            }
            if (page == WebWizard.WizardSteps.IndexOf(this.FAQ))
            {
                return;
            }
            if (page == WebWizard.WizardSteps.IndexOf(this.Disposition))
            {

                return;
            }
        }
        catch (Exception ex)
        {
            lblException.Visible = true;
            lblException.Text = ex.ToString();
        }


    }

    //PRE-LOGIC
    protected void WebWizard_ActiveStepChanged(object sender, EventArgs e)
    {
        lblError.Visible = false;
        lblError.Text = "";
        if (WebWizard.ActiveStep.ID.ToString() == "Introduction")
        {
            
        }
        if (WebWizard.ActiveStep.ID.ToString() == "MailLetter")
        {
            if (string.IsNullOrEmpty(txtNumberOfChildren.Text) && string.IsNullOrEmpty(txtOneTimeDonationAmt.Text))
                WebWizard.ActiveStepIndex = 2;
        }
        if (WebWizard.ActiveStep.ID.ToString() == "ChildSponsor")
        {
            if (!string.IsNullOrEmpty(txtNumberOfChildren.Text))
            {
                litNumberOfChildren.Text = txtNumberOfChildren.Text;
                txtOneTimeDonationAmt.Text = "";
                litCallTotalAmount.Text = Convert.ToString(Convert.ToInt32(txtNumberOfChildren.Text) * 15);
            }
            else
            {
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.OneTime);
            }

        }

        if (WebWizard.ActiveStep.ID.ToString() == "OneTime")
        {
            txtNumberOfChildren.Text = "";

        }
        if (WebWizard.ActiveStep.ID.ToString() == "Rebuttals")
        {

        }
        if (WebWizard.ActiveStep.ID.ToString() == "FAQ")
        {

        }
        if (WebWizard.ActiveStep.ID.ToString() == "Disposition")
        {
            
            if (!string.IsNullOrEmpty(txtOneTimeDonationAmt.Text))
            {
                App.PutCallData("OneTimeAmount", txtOneTimeDonationAmt.Text.Replace(",", "").Replace("$", "").Replace(".00", ""));
            App.PutCallData("ChildrenToSponsor", "");
            App.PutCallData("MonthlySponsorship", "");
            switch (ddlPaymentType.SelectedValue)
            {
                case "No":
                    App.PutCallData("webusercode", "H1");
                    lblDisposition.Text = "Mail Letter - One Time Payment";
                    break;
                case "CC":
                    App.PutCallData("webusercode", "H2");
                    lblDisposition.Text = "Credit Card - One Time Payment";
                    break;
            }
            }
            else
            {
                if (!string.IsNullOrEmpty(txtNumberOfChildren.Text))
                {
                    App.PutCallData("ChildrenToSponsor", txtNumberOfChildren.Text.Replace(",", ""));
                    App.PutCallData("MonthlySponsorship", Convert.ToString(Convert.ToInt32(txtNumberOfChildren.Text.Replace(",", "")) * 15));
                    App.PutCallData("OneTimeAmount", "");
                    switch (ddlPaymentType.SelectedValue)
                    {
                        case "No":
                            App.PutCallData("webusercode", "H3");
                            lblDisposition.Text = "Mail Letter - Sponsorship";
                            break;
                        case "CC":
                            App.PutCallData("webusercode", "H4");
                            lblDisposition.Text = "Credit Card - Sponsorship";
                            break;
                    }
                }
                else
                {
                    lblError.Text += " You must imput either a One-Time donation or a Sponsorship of XX Children to Continue.";
                    lblError.Visible = true;
                    WebWizard.ActiveStepIndex = Sender;
                    
                }
            }

            if (SubmitData())
            {
                App.CommitCallData();
                DispoConfirm1.Visible = false;
                Button2.Visible = false;
            }
            else
            {
                WebWizard.ActiveStepIndex = Sender;
                lblError.Text += "You do not have all required data";
                lblError.Visible = true;
                Button2.Visible = true;
            }
        }

    }

    //Payment Logic
    protected bool SubmitData()
    {
        lblError.Text = "";

        bool bCustValid = false;
        bool ccCheck = false;
        bool ecCheck = false;
        bool bShipValid = false;
        int yearval = Convert.ToInt32(DateTime.Today.ToString("yy"));
        //int result;


        
        //if There is going to be a payment.
        if (ddlPaymentType.SelectedValue != "No")
        {
            if (tbExpDate.Text.Length == 4)
            {
                ccCheck = !(string.IsNullOrEmpty(ddlCardType.SelectedItem.Text) ||
                    string.IsNullOrEmpty(tbCCNumber.Text) ||
                    //string.IsNullOrEmpty(tbCCV.Text) ||
                    string.IsNullOrEmpty(tbExpDate.Text) ||
                    (Convert.ToInt32(tbExpDate.Text.Substring(2, 2)) == yearval && Convert.ToInt32(tbExpDate.Text.Substring(0, 2)) < Convert.ToInt32(DateTime.Today.ToString("MM")))) &&
                    (Convert.ToInt32(tbExpDate.Text.Substring(2, 2)) >= yearval) &&
                    (Convert.ToInt32(tbExpDate.Text.Substring(2, 2)) <= (yearval + 10)) &&
                    (Convert.ToInt32(tbExpDate.Text.Substring(0, 2)) >= 1 && Convert.ToInt32(tbExpDate.Text.Substring(0, 2)) <= 12) &&
                    (System.Text.RegularExpressions.Regex.IsMatch(tbExpDate.Text, @"^[\d]+$"));
            }
            else
            {
                ccCheck = false;
                return false;
            }

            ecCheck = !(string.IsNullOrEmpty(tbBankName.Text) ||
                string.IsNullOrEmpty(tbAccHolder.Text) ||
                string.IsNullOrEmpty(tbAccNum.Text) ||
                string.IsNullOrEmpty(tbRoutNum.Text) ||
                string.IsNullOrEmpty(tbCheckNum.Text)) &&
                (System.Text.RegularExpressions.Regex.IsMatch(tbAccNum.Text, @"^[\d]+$")) &&
                (System.Text.RegularExpressions.Regex.IsMatch(tbRoutNum.Text, @"^[\d]+$")) &&
                (System.Text.RegularExpressions.Regex.IsMatch(tbCheckNum.Text, @"^[\d]+$")) &&
                App.ValidateRoutingNumber(Convert.ToInt32(tbRoutNum.Text));

            if (ddlPaymentType.SelectedIndex == 1) // debit/credit
            {
                App.PutCallData("PaymentType", ddlPaymentType.SelectedItem.Value);

                if (ccCheck)
                {
                    App.PutCallData("CCType", ddlCardType.SelectedItem.Value);
                    App.PutCallData("CCNumber", App.EnryptData(tbCCNumber.Text).Replace(",", ""));
                    App.PutCallData("CCExpDate", App.EnryptData((tbExpDate.Text.Substring(0, 2) + "/" + tbExpDate.Text.Substring(2, 2))));

                }
                else
                {
                    lblError.Text += "Invalid Card Info<br/>";
                    return false;
                }
            }
            else if (ddlPaymentType.SelectedIndex == 2) // echeck
            {
                App.PutCallData("PaymentType", ddlPaymentType.SelectedItem.Value.Replace(",", ""));

                if (ecCheck)
                {
                    App.PutCallData("BankName", tbBankName.Text.Replace(",", ""));
                    App.PutCallData("NameOnAccount", tbAccHolder.Text.Replace(",", ""));
                    App.PutCallData("AccountNumber", tbAccNum.Text.Replace(",", ""));
                    App.PutCallData("RoutingNumber", tbRoutNum.Text.Replace(",", ""));
                    App.PutCallData("CheckNumber", tbCheckNum.Text.Replace(",", ""));
                    App.PutCallData("AccountType", ddlAccType.SelectedItem.Text.Replace(",", ""));
                }
                else
                {
                    lblError.Text += "Invalid Bank Info<br/>";
                    return false;
                }
            }
            else
            {
                lblError.Text += "Please select a payment method." + Environment.NewLine;
                return false;
            }
        }

        //if (bCustValid && (ccCheck || ecCheck))
        //{
        //    if (!cbShipping.Checked || bShipValid)
        //    {
        //        Session["CInfo"] = true;

        //    }
        //    else
        //    {
        //        Session["CInfo"] = false;
        //    }
        //}
        //else
        //{
        //    Session["CInfo"] = false;
        //}
            bCustValid = !(string.IsNullOrEmpty(tbFirstName.Text) ||
            string.IsNullOrEmpty(tbLastName.Text) ||
            string.IsNullOrEmpty(tbAddr.Text) ||
            (tbAddr.Text == "PO BOX ") ||
            string.IsNullOrEmpty(tbZip.Text) ||
            string.IsNullOrEmpty(ddlCity.SelectedItem.Text) ||
            string.IsNullOrEmpty(ddlState.SelectedItem.Text) ||
            string.IsNullOrEmpty(ddlCountry.SelectedItem.Text)) &&
            (ddlCity.SelectedIndex > 0);

            bShipValid = !(string.IsNullOrEmpty(tbShipAddr.Text) ||
            (tbShipAddr.Text == "PO BOX ") ||
            string.IsNullOrEmpty(tbShipZip.Text) ||
            string.IsNullOrEmpty(ddlShipCity.SelectedItem.Text) ||
            string.IsNullOrEmpty(ddlShipState.SelectedItem.Text) ||
            string.IsNullOrEmpty(ddlShipCountry.SelectedItem.Text)) &&
            (ddlShipCity.SelectedIndex > 0) &&
            (tbShipZip.Text.Length >= 5) &&
            (tbShipZip.Text.Length <= 7);



        if (bCustValid)
        {
            App.PutCallData("FirstName", tbFirstName.Text.Replace(",", ""));
            App.PutCallData("LastName", tbLastName.Text.Replace(",", ""));
            App.PutCallData("Address", tbAddr.Text.Replace(",", ""));
            if (!string.IsNullOrEmpty(tbAddr2.Text))
                App.PutCallData("Address2", tbAddr2.Text.Replace(",", ""));
            else
                App.PutCallData("Address2", "");
            App.PutCallData("Zip", tbZip.Text.Replace(",", ""));
            App.PutCallData("City", ddlCity.SelectedItem.Text.Replace(",", ""));
            App.PutCallData("State", ddlState.SelectedItem.Text);
            App.PutCallData("Country", ddlCountry.SelectedItem.Text);

            //this is what happens if the shipping info is not visible
            if (!cbShipping.Checked)
            {
                App.PutCallData("ShippingAddress", tbAddr.Text.Replace(",", ""));
                if (!string.IsNullOrEmpty(tbAddr2.Text))
                    App.PutCallData("ShippingAddress2", tbAddr2.Text.Replace(",", ""));
                else
                    App.PutCallData("ShippingAddress2", "");
                App.PutCallData("ShippingZip", tbZip.Text.Replace(",", ""));
                App.PutCallData("ShippingCity", ddlCity.SelectedItem.Text.Replace(",", ""));
                App.PutCallData("ShippingState", ddlState.SelectedItem.Text);
                App.PutCallData("ShippingCountry", ddlCountry.SelectedItem.Text);
            }
            else
            {
                if (bShipValid)
                {
                    App.PutCallData("ShippingAddress", tbShipAddr.Text.Replace(",", ""));
                    if (!string.IsNullOrEmpty(tbShipAddr.Text))
                        App.PutCallData("ShippingAddress2", tbShipaddr2.Text.Replace(",", ""));
                    else
                        App.PutCallData("ShippingAddress2", "");
                    App.PutCallData("ShippingZip", tbShipZip.Text.Replace(",", ""));
                    App.PutCallData("ShippingCity", ddlShipCity.SelectedItem.Text.Replace(",", ""));
                    App.PutCallData("ShippingState", ddlShipState.SelectedItem.Text);
                    App.PutCallData("ShippingCountry", ddlShipCountry.SelectedItem.Text);
                }
                else
                {
                    lblError.Text += "Enter Shipping Info<br/>";
                    return false;
                }
            }
        }
        else
        {
            if (tbAddr.Text == "PO BOX ")
            {
                lblError.Text += "Enter a PO BOX number <br/>";
                return false;
            }
            else
            {
                if (ddlCity.Items.Count > 1 && ddlCity.SelectedIndex == 0)
                    lblError.Text += "Select a City<br/>";
                else
                    lblError.Text += "Enter Valid Customer Data<br/>";
                return false;
            }
        }

        if ((!string.IsNullOrEmpty(tbPhone.Text)) && ((tbPhone.Text.Length != 10) || !(System.Text.RegularExpressions.Regex.Match(tbPhone.Text, @"^[1-9]\d{2}[1-9]\d{6}$").Success)))
        {
            lblError.Text += "Invalid Phone<br/>";
            return false;
        }
        else
        {
            if (!string.IsNullOrEmpty(tbPhone.Text))
                App.PutCallData("Phone", tbPhone.Text);
        }

        if ((!string.IsNullOrEmpty(tbEmail.Text)) && !App.IsValidEmail(tbEmail.Text))
        {
            lblError.Text += "Invalid Email<br/>";
            return false;
        }
        else
        {
            if (!string.IsNullOrEmpty(tbEmail.Text))
                App.PutCallData("Email", tbEmail.Text);
        }

        if (cbShipping.Checked)
        {
            if (tbShipAddr.Text.Replace(".", "").Replace(" ", "").Length >= 5)
            {
                if (tbShipAddr.Text.Replace(".", "").Replace(" ", "").Substring(0, 5).ToUpper() == "POBOX")
                {
                    App.PutCallData("ShippingAddress", tbShipAddr.Text.Replace(",", "").Replace(".", ""));
                }
                else
                {

                }
            }
        }
        else
        {
            if (tbAddr.Text.Replace(".", "").Replace(" ", "").Length >= 5)
            {
                if (tbAddr.Text.Replace(".", "").Replace(" ", "").Substring(0, 5).ToUpper() == "POBOX")
                {
                    App.PutCallData("ShippingAddress", tbAddr.Text.Replace(",", "").Replace(".", ""));
                    App.PutCallData("Address", tbAddr.Text.Replace(",", "").Replace(".", ""));
                }
                else
                {

                }
            }

        }


        
        return true;
    }

    ///***************************
    protected void ddlPaymentType_SelectedIndexChanged(object sender, EventArgs e)
    {

        if (string.IsNullOrEmpty(txtOneTimeDonationAmt.Text) && string.IsNullOrEmpty(txtNumberOfChildren.Text) )
        {
            lblError.Text = " You must enter a value for Number of Children OR One Time Donation Amount ";
            lblError.Visible = true;
            ddlPaymentType.SelectedIndex = 0;
        }
        else
        {
            App.PutCallData("PaymentType", ddlPaymentType.SelectedItem.Value);
            if (ddlPaymentType.SelectedValue == "CC")
            {
                trCCNumber.Visible = true;
                trCCType.Visible = true;
                trCCExpDate.Visible = true;

                trECAccNum.Visible = false;
                trECBankName.Visible = false;
                trECCheckNum.Visible = false;
                trECRoutNum.Visible = false;
                trECAccType.Visible = false;
                trECAccHolder.Visible = false;
                tbAccHolder.Text = "";
                tbAccNum.Text = "";
                tbBankName.Text = "";
                tbRoutNum.Text = "";
                tbCheckNum.Text = "";



            }
            else if (ddlPaymentType.SelectedValue == "EC")
            {
                trCCNumber.Visible = false;
                trCCType.Visible = false;
                trCCExpDate.Visible = false;
                //trCCV.Visible = false;
                trECAccNum.Visible = true;
                trECBankName.Visible = true;
                trECCheckNum.Visible = true;
                trECRoutNum.Visible = true;
                trECAccType.Visible = true;
                trECAccHolder.Visible = true;
                tbCCNumber.Text = "";
                tbExpDate.Text = "";

            }
            else //They changed it from EC or CC to blank
            {
                trCCNumber.Visible = false;
                trCCType.Visible = false;
                trCCExpDate.Visible = false;
                trECAccNum.Visible = false;
                trECBankName.Visible = false;
                trECCheckNum.Visible = false;
                trECRoutNum.Visible = false;
                trECAccType.Visible = false;
                tbCCNumber.Text = "";
                tbExpDate.Text = "";
                tbAccHolder.Text = "";
                tbAccNum.Text = "";
                tbBankName.Text = "";
                tbRoutNum.Text = "";
                tbCheckNum.Text = "";

            }
        }
        if (ddlPaymentType.SelectedValue == "No")
        {
            WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.MailLetter);
        }

    }

    protected void cbShipping_CheckedChanged(object sender, EventArgs e)
    {
        if (cbShipping.Checked)
        {

            trShipAddr.Visible = true;
            trShipAddr2.Visible = true;
            trShipPOBoxOption.Visible = true;
            trShipCity.Visible = true;
            trShipState.Visible = true;
            trShipCountry.Visible = true;
            trShipZip.Visible = true;
            trShipLbl.Visible = true;
            trShipSearchZip.Visible = true;

        }
        else
        {
            trShipAddr.Visible = false;
            trShipAddr2.Visible = false;
            trShipPOBoxOption.Visible = false;
            trShipCity.Visible = false;
            trShipState.Visible = false;
            trShipCountry.Visible = false;
            trShipZip.Visible = false;
            trShipLbl.Visible = false;
            trShipSearchZip.Visible = false;
        }
    }

    protected void cbPOBox_CheckedChanged(object sender, EventArgs e)
    {

        tbAddr.Text = "";
        tbAddr2.Text = "";
        if (cbPOBox.Checked)
        {
            Page.SetFocus(tbAddr);
            tbAddr.Text = "PO BOX ";
            trAddr2.Visible = false;
        }
        else
        {
            trAddr2.Visible = true;
        }
    }
    protected void cbShipPOBox_CheckedChanged(object sender, EventArgs e)
    {
        tbShipAddr.Text = "";
        tbShipaddr2.Text = "";
        if (cbShipPOBox.Checked)
        {
            tbShipAddr.Text = "PO BOX ";
            trShipAddr2.Visible = false;
            Page.SetFocus(tbShipAddr);
        }
        else
        {
            trShipAddr2.Visible = true;
        }
    }

    protected void btnSearchZip_Click(object sender, EventArgs e)
    {
        ValidateZip(tbZip.Text.ToUpper(), ddlCity, ddlState, ddlCountry);
        if (cbShipping.Checked)
        {
            if (ddlShipCountry.SelectedItem.Text == "CANADA")
            {
                ddlPaymentType.Items[2].Enabled = false;
            }
        }
        else if (ddlCountry.SelectedItem.Text == "CANADA")
        {
            ddlPaymentType.Items[2].Enabled = false;
        }
        else
        {
            ddlPaymentType.Items[2].Enabled = true;
        }
    }

    protected void btnShipSearchZip_Click(object sender, EventArgs e)
    {
        ValidateZip(tbShipZip.Text.ToUpper(), ddlShipCity, ddlShipState, ddlShipCountry);
        if (cbShipping.Checked)
        {
            if (ddlShipCountry.SelectedItem.Text == "CANADA")
            {
                ddlPaymentType.Items[2].Enabled = false;
            }
            else
            {
                ddlPaymentType.Items[2].Enabled = true;
            }
        }
    }

    protected void ValidateZip(string strZip, DropDownList ddl_City, DropDownList ddl_State, DropDownList ddl_Country)
    {

        ddl_City.Items.Clear();
        ddl_State.Items.Clear();
        ddl_City.Enabled = true;
        ddl_State.Enabled = true;

        if (System.Text.RegularExpressions.Regex.IsMatch(strZip.ToUpper(), @"(^\d{5}$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} +\d{1}[A-Z]{1}\d{1}$)"))
        {
            try
            {
                com.codebump.GeoPlaces g = new com.codebump.GeoPlaces();

                com.codebump.AuthenticationHeader authHeader = new com.codebump.AuthenticationHeader();
                authHeader.SessionID = "6JV2ZA4lgG1YRR+HG+JU27QWk9zI3rpRWY2iG2mzNPcdieEQXfQv0OUY0EZ+pOTxhwI1NCuF7b2oY+U/bozy0mhjFHmpaXvb";
                g.AuthenticationHeaderValue = authHeader;

                com.codebump.GeoPlaceDistance[] places = g.GetPlacesInside(strZip, "");

                for (int i = 0; i < places.Length; i++)
                {
                    com.codebump.GeoPlaceDistance place = places[i];
                    ListItem li = new ListItem(place.ToPlace, place.ToState + "," + place.ToPlace);
                    ddl_City.Items.Add(li);
                }

                ddl_State.Items.Add(ddl_City.SelectedItem.Value.Split(",".ToCharArray())[0]);

                //ddlCity.SelectedIndex = 0;

                if (System.Text.RegularExpressions.Regex.IsMatch(strZip.ToUpper(), @"(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)"))
                {
                    ddl_Country.SelectedValue = "CANADA";
                }
                else
                {
                    ddl_Country.SelectedValue = "USA";
                }

                if (ddl_City.Items.Count <= 0)
                {
                    ddl_City.Items.Add("No Cities Found");
                    ddl_State.Items.Add("No States Found");
                    ddl_City.Enabled = false;
                    ddl_State.Enabled = false;
                }
                else
                {
                    ddl_City.Items.Insert(0, "Select a City");
                    ddl_City.SelectedIndex = 0;
                    ddl_State.Enabled = false;
                }
            }
            catch
            {
                ddl_City.Items.Add("No Cities Found");
                ddl_State.Items.Add("No States Found");
                ddl_City.Enabled = false;
                ddl_State.Enabled = false;
            }
        }
        else
        {
            ddl_City.Items.Add("Invalid Zip");
            ddl_City.Enabled = false;
            ddl_State.Items.Add("Invalid Zip");
            ddl_State.Enabled = false;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Button2.Visible = true;
        WebWizard.ActiveStepIndex = 2;
        txtNumberOfChildren.Text = "";
        txtOneTimeDonationAmt.Text = "";
        ddlPaymentType.SelectedIndex = 0;
        tbCCNumber.Text = "";
            tbExpDate.Text = "";
        App.PutCallData("OneTimeAmount", "");
        App.PutCallData("ChildrenToSponsor", "");
        App.PutCallData("MonthlySponsorship", "");
        App.PutCallData("PaymentType", "");
        App.PutCallData("CCNumber", "");
        App.PutCallData("CCExpDate", "");
        App.PutCallData("webusercode", "");
        App.CommitCallData();

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        DispoConfirm1.Visible = true;
        Button2.Visible = false;
        App.CommitCallData();
    }
    protected void cmdSubmitNameAndAddress_Click(object sender, EventArgs e)
    {
        App.CommitCallData();
    }
    protected void txtOneTimeDonationAmt_TextChanged(object sender, EventArgs e)
    {

        txtOneTimeDonationAmt.Text = txtOneTimeDonationAmt.Text.Replace(",", "").Replace("$", "").Replace(".00", "");
    }
}